<?php View::render('admin/layouts/meta'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo Router::getBaseUrl();?>/assets/js/webuploader.css" />
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-member-add">
        <!-- 所在城市 -->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>所在城市：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box" style="width: 200px;">
                <select class="select" name="local_province">
                    <?php if ($is_update ==0) {?>
                        <option value="0">==省份==</option>
                    <?php } ?>
                    <?php foreach ($province as $pro) {?>
                        <option value="<?php echo $pro['id']; ?>" <?php if ($edit_info && $edit_info['province'] == $pro['id']) {echo 'selected="selected"';}?>>==<?php echo $pro['name']; ?>==</option>
                    <?php }?>
                </select>
                </span>
                <span class="select-box" style="width: 200px;">
                <select class="select" name="local_city">
                    <?php if ($is_update ==0) {?>
                    <option value="0">==城市==</option>
                    <?php } ?>
                    <?php foreach ($city as $cit) {?>
                        <option value="<?php echo $cit['id']; ?>" <?php if ($edit_info && $edit_info['city'] == $cit['id']) {echo 'selected="selected"';}?>>==<?php echo $cit['name']; ?>==</option>
                    <?php }?>
                </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <ul class="tpl-task-list ml-20">
                <li>
                    <div class="task-title mb-10" style="margin-left:100px;">
                        <label>
                             <span style="margin-left:50px;width: 500px" id="replace">
                                <?php if($area) {foreach ($area as $key => $item){?>
                                    <?php if ($key%5==0){?> <br/><?php }?>
                                    <label style="width:200px;display:inline-block;margin-right:20px;"><input type="checkbox" name="node[]" value="<?php echo $item['id'];?>" rel="<?php echo $item['id'];?>" class="node_cell node_row_<?php echo $item['id'];?> node_item_<?php echo $item['id'];?>" <?php echo in_array($item['id'], $node_list)? 'checked="checked" disabled="true"' :'';?>/> <?php echo $item['name'];?> </label>
                                <?php }}?>
                             </span>
                        </label>
                    </div>
                </li>
            </ul>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input type="hidden" name="id" value="<?php echo $edit_info ? $edit_info['id'] : 0; ?>" />
                <input class="btn btn-primary radius" type="button" id="j_submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
	</form>
</article>
</body>
<?php View::render('admin/layouts/footer'); ?>
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl();?>/assets/js/webuploader.min.js"></script>
<script type="text/javascript">
$(function(){
    /** 所属地区 **/
    $("select[name=local_province]").on('change',function(){
        var region_id =$(this).val();
        $.ajax({
            url:"/Region/getCity",
            type:"get",
            data:{provinceId:region_id},
            success:function(data, textStatus){
                data = $.parseJSON(data);
                if(data.status==200){
                    var str = '';
                    $.each(data.data,function(index,val){
                        str+="<option value='"+val.id+"'>"+val.name+"</option>";
                    });
                    $("select[name='local_area'] option:gt(0)").remove();
                    $("select[name='local_city'] option:gt(0)").remove();
                    $("select[name='local_city']").append(str);
                    $("#replace").html('');
                }
            }
        })
    });
    $("select[name=local_city]").on('change',function(){
        var region_id =$(this).val();
        $.ajax({
            url:"/Region/getArea",
            type:"get",
            data:{cityId:region_id},
            success:function(data, textStatus){
                data = $.parseJSON(data);
                if(data.status==200){
                    var str = '';
                    $.each(data.data,function(index,val){
                        if (index%5 == 0) {
                            str+='</br><label style="width:200px;display:inline-block;margin-right:20px;"><input type="checkbox" name="node[]" value="'+val.id+'" rel="'+val.id+'" class="node_cell node_row_'+val.id+' node_item_'+val.id+'" "'+val.is_checked+'">'+val.name+'</label>';
                        } else {
                            str+='<label style="width:200px;display:inline-block;margin-right:20px;"><input type="checkbox" name="node[]" value="'+val.id+'" rel="'+val.id+'" class="node_cell node_row_'+val.id+' node_item_'+val.id+'" "'+val.is_checked+'">'+val.name+'</label>';
                        }
                    });
                    $("#replace").html('');
                    $("#replace").html(str);
                }
            }
        })
    });
    /** 所属地区 **/


    $('#j_submit').click(function () {
        //去掉disabled属性
        // $(".select").removeAttr("disabled");
        // $(".node_cell").removeAttr("disabled");
            var $btn = $(this);
            $btn.button('loading');
            $.post('/admin_business/edit', $('form').serialize(), function (result) {
                if (result.status == 200) {
                    layer.msg(result.msg, {
                        icon: 1, //0-6
                        //anim:2,
                        skin: 'u-msg',
                        time: 1200,
                    },function(){
                        var index = parent.layer.getFrameIndex(window.name); 
                        parent.layer.close(index);
                        parent.window.location.href=parent.window.location.href;
                    });

                }else{
                    layer.msg(result.msg, {
                        icon: 0, //0-6
                        //anim:2,
                        skin: 'u-msg',
                        time: 3000,
                    }, function () {
                        //do things
                    });
                }
                $btn.button('reset');
            }, 'json');
            return;
        });


        //全选
        $(".node_row").each(function(){
          $(this).on("click",function(){
            var id = $(this).attr('value');
            var checked = !!$(this).is(":checked");
            $(".node_row_"+id).prop('checked',checked);
          })
        });
        $(".node_item").each(function(){
          $(this).on("click",function(){
            var pid = $(this).attr('rel');
            var id = $(this).attr('value');
            var checked = !!$(this).is(":checked");
            if(checked==true) {
                $('input[value="'+pid+'"]').prop('checked', checked);
            }
            $(".node_item_"+id).prop('checked',checked);
           
          })
        });
        
        $(".node_cell").each(function(){
          $(this).on("click",function(){
            var pid = $(this).attr('rel');
            var checked = !!$(this).is(":checked");
            if(checked==true) {
                $('input[value="'+pid+'"]').prop('checked', true);
            }
          })
        });
});
</script>
</html>